import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

/* Layout */

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'Home',
    alwaysShow: true,
    children: [{
      path: '/home',
      name: 'homePage',
      component: () => import('@/views/home/index'),
      meta: {
        title: '首页',
        icon: 'dashboard'
      }
    }]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/list',
    name: 'Article',
    meta: {
      title: '文章管理',
      icon: 'el-icon-document'
    },
    children: [{
      path: '/article/list',
      name: 'ArticleList',
      component: () => import('@/views/article/index'),
      meta: {
        title: '文章管理'
      }
    },
    {
      path: '/article/category',
      name: 'ArticleCategory',
      component: () => import('@/views/article/category'),
      meta: {
        title: '文章分类'
      }
    }]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '多级菜单',
      icon: 'el-icon-s-operation'
    },
    children: [{
      path: '/nested/menu1',
      alwaysShow: true,
      redirect: '/nested/menu1/menu1-1',
      component: () => import('@/views/nested/menu1/index'),
      name: 'Menu1',
      meta: {
        title: '二级菜单'
      },
      children: [
        {
          path: '/nested/menu1/menu1-1',
          component: () => import('@/views/nested/menu1/menu1-1/index'),
          name: 'Menu1-1',
          meta: {
            title: '三级菜单1'
          }
        },
        {
          path: '/nested/menu1/menu1-2',
          component: () => import('@/views/nested/menu1/menu1-1/index'),
          name: 'Menu1-2',
          meta: {
            title: '三级菜单2'
          }
        }
      ]
    },
    {
      path: '/site/index',
      name: 'Site',
      component: () => import('@/views/site/index'),
      meta: {
        title: '站点设置'
      }
    }]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: '/setting/user',
    name: 'Setting',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools'
    },
    children: [
      {
        path: '/setting/user',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'external-link',
        component: Layout,
        alwaysShow: true,
        children: [{
          path: 'https://panjiachen.gitee.io/vue-element-admin-site/zh/',
          meta: {
            title: '框架文档',
          }
        }]
      },
    ]
  },
  
  {
    path: '/404',
    component: () => () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  // const newRouter = createRouter()
  // router.matcher = newRouter.matcher // reset router
}

export default router
